<template>
    <div class="tips" v-if="evnFlag==1">
        <img src="/images/wechattips.jpg" alt="">
    </div>
</template>

<script>
import { reactive,toRefs,getCurrentInstance,onMounted } from 'vue'
import {useRoute,useRouter} from 'vue-router'
import { useStore } from 'vuex'
import {loading} from '@/utils/common'
export default {
    props:{

    },
    components:{
        
    },
    setup(props,context){
        const router = useRouter()
        const route = useRoute()
        const store = useStore()
        const {proxy} = getCurrentInstance()

        const state = reactive({
            evnFlag:'', // 1为微信中打开，2为ios，3为安卓
            gid:''
        })

        onMounted(()=>{
            state.gid = route.query.id
            init()
        })

        const init = ()=>{
            let ua = window.navigator.userAgent.toLowerCase()
            // 微信
            if(ua.match(/MicroMessenger/i) == 'micromessenger'){
                state.evnFlag = 1
                loading.close()
                //window.location.href = '***'  // 直接跳转到应用宝的下载链接
            }else{ // 非微信浏览器
                if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
                    state.evnFlag = 2
                    let ifr = document.createElement('iframe')
                    ifr.src = 'weixin://' // 打开app协议地址，ios开发提供
                    ifr.style.display = 'none'
                    document.body.appendChild(ifr)
                    setTimeout(()=>{
                        loading.close()
                        document.body.removeChild(ifr)
                        window.location.href = "https://apps.apple.com/cn/app/%E5%85%83%E7%95%8C-ar/id1631516341" // ios下载app的地址
                    },2000)
                }else if(navigator.userAgent.match(/android/i)){
                    state.evnFlag = 3
                    try {
                        loading.close()

                        window.location = 'https://www.tst.metayuanjie.com/h5/collection' // 临时加的

                        // window.location = 'weixin://' // 安卓开发提供的打开app协议
                        // setTimeout(()=>{
                        //     window.location = 'https://www.tst.metayuanjie.com/h5/collection'  // 安卓下载地址
                        // },2000)
                    } catch (error) {
                        
                    }
                }
            }
        }

        return{
            ...toRefs(state)
        }
    }
}
</script>

<style lang="scss" scoped>
    .tips{
        position: fixed;
        width: 100%;
        height: 100%;
        background: #fff;
        img{
            display: block;
            width: 100%;
        }
    }
</style>